package day240130;

import java.util.Scanner;

public class HalfSearch {
    public static void main(String[] args) {
        int[] arr = new int[]{3, 4, 5, 6, 7, 8, 9, 10, 12};
        //int target = 7;
        System.out.println("请输入要查找的数：");
        Scanner scanner = new Scanner(System.in);
        int target = scanner.nextInt();

        int low = 0;
        int high = arr.length - 1;

        int middle = (low + high) / 2 ;

        boolean flag = false;
        while (low <= high){
            if (arr[middle] == target){
                flag = true;
                break;
            }
            else if (arr[middle] < target){
                low = middle + 1;
                middle = (low + high) / 2;
            }
            else {
                high = middle - 1;
                middle = (low + high) / 2;
            }
        }

        if(flag){
            System.out.println("在index为" + middle + "处找到");
        }
        else {
            System.out.println("没有找到");
        }
    }
}
